package com.woniuxy.orderserver.controller;
import com.woniuxy.common.dto.SkuDto;
import com.woniuxy.orderserver.feign.ProductFeign;
import com.woniuxy.orderserver.pojo.FinanceOrder;
import com.woniuxy.orderserver.service.FinanceOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "订单服务API")
public class OrderController {
    @Autowired
    private FinanceOrderService financeOrderService;

    @Autowired
    private ProductFeign productFeign;


    @GetMapping("/query/{id}")
    @ApiOperation(value = "查询商品信息",notes = "根据skuid查询商品信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "商品id",required = true,dataType = "int")
    })
    public SkuDto queryByid(@PathVariable("id") Integer id){
        return productFeign.queryByid(id);
    }

    @PostMapping("/addOrder1")
    public void addOrder(FinanceOrder financeOrder){
        financeOrderService.save(financeOrder);
    }

    @GetMapping("/updateStock")
    void updateStock(){
        productFeign.updateStock();
    }

    /**
     * 下单
     * @param skuId
     * @return
     */
    @PostMapping("/addOrder")
    public String addOrder(Integer skuId){
        return financeOrderService.addOrder(skuId);
    }

}
